import Vue from 'vue'
import store from 'vuex'
import { formatTen } from '../assets/js/help.js'

// let langObj = JSON.parse(localStorage.getItem('langObj'));
let _day =  '天';
let _hour = '时';
let _minute = '分';
// if(langObj) {
//   _day =  langObj.normal_label_time_day || '天';
//   _hour = langObj.normal_label_time_hour || '时';
//   _minute = langObj.normal_label_time_minute || '分';
// }

//毫秒转日期  yyyy-MM-dd hh:mm:ss
Vue.filter('mileSecondToDate', function(value) {
  let result = '';
  if(value) {
    let date = new Date(value);
    result =  date.getFullYear() + "-" + formatTen(date.getMonth() + 1) + "-" + formatTen(date.getDate()) + " " + formatTen(date.getHours()) + ":" + formatTen(date.getMinutes()) + ":" + formatTen(date.getSeconds());
  }
  return result;
})

//分钟转 XX天XX时XX分
Vue.filter('minutesToHowLong', function (Val) {
  let mits = Val < 0 ? 0 : Val;
  //计算天数
  let days = Math.floor(mits / (60 * 24));

  //计算小时数
  let leave_d = mits % (60 * 24); //计算除去整天数后还剩下的分钟数
  let hours = Math.floor(leave_d / 60);

  //计算分钟数
  let minutes = leave_d % 60;
  
  if(days !== 0) {
    return '' + days + _day + hours + _hour + minutes + _minute;
  } else if (hours !== 0) {
    return '' + hours + _hour + minutes + _minute;
  } else {
    return '' + minutes + _minute;
  }
})

//拼接图片路径
Vue.filter('setImgPath', function(path) {
  return path ? (path.indexOf('/img') > -1 ? path : window.picPath + path) : '';
})